package com.Mt.Serviceimpl;

import com.Mt.Service.Mt_CommodityService;
import com.Mt.mapper.Mt_CommodityMapper;
import com.Mt.pojo.Mt_Commodity;
import com.Mt.pojo.Mt_CommodityAdmin;
import com.Mt.pojo.Mt_Page;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class Mt_CommodityServiceImpl implements Mt_CommodityService {

    @Autowired
    private Mt_CommodityMapper mt_commodityMapper;

    @Override
    public List<Mt_Commodity> all() {
        return mt_commodityMapper.all();
    }

    @Override
    public Mt_Page<Mt_CommodityAdmin> pageAll(int pageIndex) {
        //每页数量
        int size=10;

        //总条数
        int count = mt_commodityMapper.count();
        //一共有多少页,最后一页
        int endPage = count % size==0?count/size : count/size + 1;

        int index = (pageIndex-1)*size;

        return new Mt_Page<Mt_CommodityAdmin>(count,endPage,mt_commodityMapper.pageAll(index,size));
    }

    @Override
    public Mt_Page<Mt_CommodityAdmin> like(String cName, int pageIndex) {
        //每页数量
        int size=10;

        int count = mt_commodityMapper.count();
        int endPage = count % size==0?count/size : count/size + 1;
        int index = (pageIndex-1)*size;

        return new Mt_Page<Mt_CommodityAdmin>(count,endPage,mt_commodityMapper.like(cName,index,size));
    }

    @Override
    public int del(int id) {
        return mt_commodityMapper.del(id);
    }

    @Override
    public List<Mt_CommodityAdmin> selId(int id) {
        return mt_commodityMapper.selById(id);
    }

    @Override
    public int addCommodity(Mt_CommodityAdmin commodityAdmin) {
        return mt_commodityMapper.addCommodity(commodityAdmin);
    }
}
